package com.gao.d_selector.b;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;
import java.util.Scanner;

/**
 * @author gao
 * @time 2020/06/27 11:01:15
 */
public class Client {
    public static void main(String[] args) {
        try {
            SocketChannel socketChannel = SocketChannel.open(new InetSocketAddress("127.0.0.1", 8888));
            Scanner sc = new Scanner(System.in);
            ByteBuffer buf = ByteBuffer.allocate(1024);

            while (true) {
                System.out.println("请输入要发送给服务器的消息");
                String msg = sc.nextLine();
                buf.put(msg.getBytes());
                buf.flip();
                socketChannel.write(buf);
                buf.clear();
            }

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
